package com.eastfair.config.controller.entitycontroller;

import com.eastfair.config.entity.AppointmentPlace;
import com.eastfair.config.service.entityservice.AppointmentPlaceService;
import com.eastfair.core.base.R;
import com.eastfair.projectcore.vo.ConfigAttributeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商贸对接地点控制类
 * <p>
 * Date:2021/8/7
 * Time:15:37
 *
 * @author zjn
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/appointmentPlace")
@Api(value = "商贸对接地点控制类", tags = "商贸对接地点控制类")
public class AppointmentPlaceController {

    @Autowired
    private AppointmentPlaceService appointmentPlaceService;

    /**
     * 获取商贸对接地点属性信息
     *
     * @return
     */
    @GetMapping("/getAttributes")
    @ApiOperation(value = "获取商贸对接地点属性信息", notes = "获取商贸对接地点属性信息")
    public R<List<ConfigAttributeVO>> getAppointmentPlaceAttributes() {
        return R.success(appointmentPlaceService.getAttributes());
    }

    /**
     * 获取商贸对接地点列表
     *
     * @param appointmentPlace 商贸对接地点列表过滤条件
     * @return
     */
    @PostMapping("/getList")
    @ApiOperation(value = "获取商贸对接地点列表", notes = "获取商贸对接地点列表")
    public R<List<AppointmentPlace>> getList(@RequestBody(required = false) AppointmentPlace appointmentPlace) {
        return R.success(appointmentPlaceService.getList(appointmentPlace));
    }

    /**
     * 获取商贸对接地点
     *
     * @param flagId 标识id
     * @return
     */
    @GetMapping("/get/{flagId}")
    @ApiOperation(value = "获取商贸对接地点", notes = "获取商贸对接地点")
    public R<AppointmentPlace> getAppointmentPlace(@PathVariable("flagId") Long flagId) {
        return appointmentPlaceService.get(flagId);
    }

    /**
     * 根据条件获取单个商贸对接地点
     * 必填参数：
     * code 编码
     *
     * @param appointmentPlace 商贸对接地点过滤条件
     * @return 商贸对接地点实体
     */
    @PostMapping("/getByEntity")
    @ApiOperation(value = "根据条件获取单个商贸对接地点", notes = "根据条件获取单个商贸对接地点")
    public R<AppointmentPlace> getByEntity(@RequestBody @Validated({AppointmentPlace.VerifyGetByEntity.class}) AppointmentPlace appointmentPlace) {
        return appointmentPlaceService.getByEntity(appointmentPlace);
    }

    /**
     * 新增商贸对接地点
     *
     * @param appointmentPlace 商贸对接地点实体
     * @return 是否成功
     */
    @PostMapping("/saveEntity")
    @ApiOperation(value = "新增商贸对接地点", notes = "新增商贸对接地点")
    public R<Boolean> saveEntity(@RequestBody AppointmentPlace appointmentPlace) {
        return appointmentPlaceService.saveEntity(appointmentPlace);
    }

    /**
     * 删除商贸对接地点
     *
     * @param flagId 商贸对接地点标识id
     * @return 是否成功
     */
    @DeleteMapping("/{flagId}")
    @ApiOperation(value = "删除商贸对接地点", notes = "删除商贸对接地点")
    public R<Boolean> deleteEntity(@PathVariable("flagId") Long flagId) {
        return appointmentPlaceService.deleteEntity(flagId);
    }

    /**
     * 修改商贸对接地点信息
     *
     * @param appointmentPlace 商贸对接地点信息
     * @return 是否成功
     */
    @PutMapping("/updateEntity")
    @ApiOperation(value = "修改商贸对接地点信息", notes = "修改商贸对接地点信息")
    public R<Boolean> updateEntity(@RequestBody AppointmentPlace appointmentPlace) {
        return appointmentPlaceService.updateEntity(appointmentPlace);
    }

}
